<template>
  <div>
    <el-form
      :model="dataForm"
      label-position="left"
      ref="dataForm"
      @keyup.enter.native="dataFormSubmit()"
      label-width="80px"
    >
      <el-form-item label="授权结果">
        <el-tag type="success">已经授权</el-tag>
        <!-- <el-tag type="success" v-if="dataForm.status == 1">完成认证</el-tag> -->
      </el-form-item>
      <el-form-item label="使用套餐">
        <el-tag v-if="dataForm.level == 1">免费使用</el-tag>
        <el-tag v-if="dataForm.level == 2">按量付费</el-tag>
        <el-tag v-if="dataForm.level == 3">按月付费</el-tag>
      </el-form-item>
      <el-form-item label="用户名">
        <el-tag>{{ dataForm.username }}</el-tag>
      </el-form-item>
      <el-form-item label="设备数">
        <el-tag>{{ dataForm.count }}</el-tag>
      </el-form-item>
      <el-form-item label="邮箱">
        <el-tag>{{ dataForm.email }}</el-tag>
      </el-form-item>
      <el-form-item label="电话">
        <el-tag>{{ dataForm.phone }}</el-tag>
      </el-form-item>
      <el-form-item label="密钥">
        <el-tag>{{ dataForm.ckey }}</el-tag>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="startToken()">设备发放</el-button>
        <el-button @click="dataFormSubmit()">授权信息</el-button>
      </el-form-item>
    </el-form>
    <!-- <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="dataFormSubmit()">取消授权</el-button>
    </span> -->
  </div>
</template>

<script>
export default {
  data() {
    return {};
  },
  props: ["dataForm"],
  methods: {
    // 表单提交
    dataFormSubmit() {
      this.$http({
        url: this.$http.adornUrl(`/iot/prod/info/${this.dataForm.consumerId}`),
        method: "get",
      }).then(({ data }) => {
        if (data && data.code === 0) {
          // console.log(data.prod);
          // productKey: "a1LpLFEJLxa"
// productName: "iotiot4"
// productSecret: "ATr3u3KqUosy6dJQ"
          this.$notify({
            title: "授权信息",
            message: `productKey: "${data.prod.productKey}"<br>productName:"${data.prod.productName}"<br>productSecret:"${data.prod.productSecret}"`,
            duration: 0,
            type: 'success',
            dangerouslyUseHTMLString: true,
          });
        } else {
          this.$message.error(data.msg);
        }
      });
    },
    startToken() {
      this.$alert(
        "是否确认生成Token？注意：在生成Token之前，需预先指定品牌和场景。",
        "提示",
        {
          confirmButtonText: "前往",
          cancelButtonText: "取消",
          showCancelButton: true,
          callback: (action) => {
            if (action === "confirm") this.$router.push("/platform-dev");
          },
        }
      );
    },
  },
};
</script>